package com.limingru.newbee.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NumberUtil {
    /**
     * 判断是否为手机号字符串
     * @param  src {String} 传入字符串
     * @return {boolean}
     */
    public static boolean isPhone(String src) {
        Pattern pattern = Pattern.compile("^((13[0-9])|(14[5,7])|(15[^4,\\D])|(17[0-8])|(18[0-9]))\\d{8}$");
        Matcher matcher = pattern.matcher(src);
        return matcher.matches();
    }

    public static int generateRandomNum(int length) {
        double random = Math.random();
        if (random < 0.1) {
            random = random + 0.1;
        }
        return (int) (random * Math.pow(10, length));
    }

    public static String generateOrderNo() {
        StringBuffer buffer = new StringBuffer(String.valueOf(System.currentTimeMillis()));
        int num = generateRandomNum(4);
        buffer.append(num);
        return buffer.toString();
    }
}
